package taiyuaneltyl.com.my_mvp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.google.gson.Gson;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.List;

import taiyuaneltyl.com.my_mvp.Bean.Bean;
import taiyuaneltyl.com.my_mvp.Bean.LoginBean;
import taiyuaneltyl.com.my_mvp.Utils.DialogUtil;
import taiyuaneltyl.com.my_mvp.Utils.LoadingDialog;
import taiyuaneltyl.com.my_mvp.View.LoginView;
import taiyuaneltyl.com.my_mvp.presenter.LoginOnListener;
import taiyuaneltyl.com.my_mvp.presenter.OnLoginListenerImpl;

public class MainActivity extends AppCompatActivity implements LoginView {
    private EditText ed_name, ed_pwd; //用户账号 密码
    private Button bt_login;         //登陆
    OnLoginListenerImpl monLoginListener = new OnLoginListenerImpl(this);  //p层的monLoginListener

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ed_name = findViewById(R.id.ed_name);
        ed_pwd = findViewById(R.id.ed_pwd);
        bt_login = findViewById(R.id.bt_login);
        bt_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                monLoginListener.login();  //p层的login
            }
        });

    }

    //请求成功 bean是结果  一下为LoginView 实现
    @Override
    public void OnSuccess(String bean) {
        Toast.makeText(MainActivity.this, "登陆成功", Toast.LENGTH_LONG).show();
        Log.v("---------", bean);

        LoginBean loginBean = new Gson().fromJson(bean, LoginBean.class);
         String s = loginBean.getData().getName();
        Log.v("---------", s);

    }
   //请求失败 msg是返回错误码
    @Override
    public void Onfail(String msg) {
        Toast.makeText(MainActivity.this, msg, Toast.LENGTH_LONG).show();
    }
     //获取用户名
    @Override
    public String getUserName() {
        return ed_name.getText().toString();
    }
   //获取密码
    @Override
    public String getPassword() {
        return ed_pwd.getText().toString();
    }
  //  获取Rid
    @Override
    public String getRid() {
        return "2131332";
    }

    //加载中显示loading
    @Override
    public void Onloading() {
        Toast.makeText(MainActivity.this, "2222", Toast.LENGTH_LONG).show();
        DialogUtil.LoadingDialog(this, "登录中...");


    }
    //加载完毕关闭loading
    @Override
    public void Ondismiss() {
        Toast.makeText(MainActivity.this, "6666666", Toast.LENGTH_LONG).show();
        DialogUtil.LoadingDialogClose();
    }


}
